//
//  HYNewFeatureCollectionViewController.swift
//  iOSWeibo
//
//  Created by why on 16/7/23.
//  Copyright © 2016年 王浩宇. All rights reserved.
//

import UIKit

private let reuseIdentifier = "Cell"

private let ItemCount = 4

class HYNewFeatureCollectionViewController: UICollectionViewController {
    
    let layout = UICollectionViewFlowLayout()
    
    init() {
        super.init(collectionViewLayout: layout)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.collectionView!.registerClass(HYNewFeatureCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
        
        setupLayout()
    }
    
    private func setupLayout() {
        layout.itemSize = self.view.frame.size
        
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        
        layout.scrollDirection = UICollectionViewScrollDirection.Horizontal
        
        collectionView?.pagingEnabled = true
        collectionView?.bounces = false
    }
}

// MARK: UICollectionViewDataSource
extension HYNewFeatureCollectionViewController {
    
    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return ItemCount
        
    }
    
    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! HYNewFeatureCollectionViewCell
        
        cell.backgroundColor = UIColor.randomColor()
        
        cell.image = UIImage(named: "new_feature_\(indexPath.item + 1)")
        
        if indexPath.item == ItemCount - 1 {
            cell.showButtons(true)
        } else {
            cell.showButtons(false)
        }
        
        return cell
    }
}
